package transfer;

import java.util.ArrayList;

/**
 * represents order state
 *
 * @author Oleh
 */
public class OrderState {

    public static final Integer ID_ENTERING = new Integer(1);
    public static final Integer ID_QUEUED = new Integer(2);
    public static final Integer ID_SHIPPING = new Integer(3);
    public static final Integer ID_CANCELED = new Integer(4);
    public static final Integer ID_DELIVERED = new Integer(5);
    public static final String NAME_ENTERING = "entering";
    public static final String NAME_QUEUED = "queued";
    public static final String NAME_SHIPPING = "shipping";
    public static final String NAME_CANCELED = "canceled";
    public static final String NAME_DELIVERED = "delivered";
    public static final OrderState ENTERING = new OrderState(ID_ENTERING, NAME_ENTERING);
    public static final OrderState QUEUED = new OrderState(ID_QUEUED, NAME_QUEUED);
    public static final OrderState SHIPPING = new OrderState(ID_SHIPPING, NAME_SHIPPING);
    public static final OrderState CANCELED = new OrderState(ID_CANCELED, NAME_CANCELED);
    public static final OrderState DELIVERED = new OrderState(ID_DELIVERED, NAME_DELIVERED);
    private Integer idOrderState;
    private String nameOrderState;

    private OrderState(Integer idOrderState, String nameOrderState) {
        this.idOrderState = idOrderState;
        this.nameOrderState = nameOrderState;
    }

    /**
     *
     * @param idOrderState
     * @return instance of OrderState
     */
    public static OrderState instance(Integer idOrderState) {
        if (idOrderState == null) {
            return null;
        }
        switch (idOrderState.intValue()) {
            case 1:
                return ENTERING;
            case 2:
                return QUEUED;
            case 3:
                return SHIPPING;
            case 4:
                return CANCELED;
            case 5:
                return DELIVERED;
            default:
                return null;
        }
    }

    public Integer getIdOrderState() {
        return idOrderState;
    }

    public String getNameOrderState() {
        return nameOrderState;
    }

    public int hashCode() {
        return idOrderState.intValue();
    }

    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final OrderState other = (OrderState) obj;
        return this.idOrderState.equals(other.idOrderState);
    }
    
    public static ArrayList getAllStates() {
        ArrayList states = new ArrayList();
        for (int i = ID_ENTERING.intValue(); i <= ID_DELIVERED.intValue(); i++) {
            states.add(instance(new Integer(i)));
        }
        return states;
    }
}
